import time

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

class Base:
    # 初始化
    def __init__(self, driver):
        self.driver = driver

    # 打开浏览器
    def open_url(self,url):
        self.driver.get(url)

    # 显示等待
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)

    # 封装点击
    def click(self,loc):
        self.find_element(loc).click()

    # 封装输入
    def send_keys(self,loc,info):
        return self.find_element(loc).send_keys(info)

    # 封装断言
    def text(self,e):
        return self.find_element(e).text

    # 等待
    def sleep(self,t):
        time.sleep(t)

    #
    def find_elements(self,loc):
        return self.driver.find_elements(*loc)

